/**
 * Created by 都大爽 on 2017/11/18.
 */
import AdminMain from '../views/admin/layout/main.vue'
import SiteMain from '../views/site/layout/main.vue'
import Util from '../libs/util'

import errorRouter from './error.js'

/**
 * 前台路由
 */
export const siteRouter = {
  path: '/',
  name: 'home',
  component: SiteMain,
  children: [
    {
      path: 'index',
      name: 'home_index',
      meta: {
        title: '首页'
      },
      component: () => import('../views/site/index.vue')
    }
  ]
}

/**
 * 后台路由
 */
export const adminRouter = [
  {
    path: '/admin/login',
    name: 'login',
    meta: {
      title: '登录',
      showOnMenu: false
    },
    component: () => import('../views/admin/auth/login.vue'),
    beforeEnter: (to, from, next) => {
      if (Util.user()) {
        next({
          name: 'admin-dashboard'
        })
      } else {
        next()
      }
    }
  },
  {
    path: '/admin',
    name: 'admin',
    component: AdminMain,
    meta: {
      requireAuth: true,
      showOnMenu: true
    },
    children: [
      {
        path: '',
        name: 'admin-dashboard',
        meta: {
          icon: 'ios-speedometer',
          title: '首页',
          showOnMenu: true
        },
        component: () => import('../views/admin/dashboard.vue')
      },
      {
        path: 'profile',
        name: 'profile',
        meta: {
          title: '个人信息'
        },
        component: () => import('../views/admin/profile.vue')
      }
    ]
  },
  {
    path: '/admin/sms',
    name: 'sms',
    component: AdminMain,
    meta: {
      requireAuth: true,
      icon: 'ios-chatboxes',
      title: '短信模块',
      showOnMenu: true
    },
    children: [
      {
        path: 'send',
        name: 'send_sms',
        meta: {
          showOnMenu: true,
          title: '短信发送',
          icon: 'ios-chatboxes',
          requirePermissions: 'edit-user',
          breadcrumbs: [{routerName: 'send_sms', title: '短信发送', active: true}]
        },
        component: () => import('../views/admin/sms_module/sms.vue')
      },
    ]
  },
  {
    path: '/admin/cms',
    name: 'cms',
    component: AdminMain,
    meta: {
      requireAuth: true,
      icon: 'key',
      title: '内容管理',
      showOnMenu: true
    },
    children: [
      {
        path: 'navigation-manager',
        name: 'navigation_manager',
        meta: {
          showOnMenu: true,
          title: '导航管理',
          icon: 'ios-navigate',
          requirePermissions: 'edit-user',
          breadcrumbs: [{routerName: 'navigation_manager', title: '导航管理', active: true}]
        },
        component: () => import('../views/admin/navigation_manager/navigation.vue')
      },
      {
        path: 'column-manager',
        name: 'column_manager',
        meta: {
          showOnMenu: true,
          title: '栏目管理',
          icon: 'android-color-palette',
          requirePermissions: 'create-post',
          breadcrumbs: [{routerName: 'column_manager', title: '栏目管理', active: true}]
        },
        component: () => import('../views/admin/column/column_num.vue')
      },
      {
        path: 'content-blog',
        name: 'content_blog',
        meta: {
          showOnMenu: true,
          icon: 'social-wordpress',
          title: '博文',
          requirePermissions: 'create-post',
          breadcrumbs: [{routerName: 'content_blog', title: '博客内容', active: true}]
        },
        component: () => import('../views/admin/content_blog/contentBlog.vue')
      },
      {
        path: 'content-picture',
        name: 'content_picture',
        meta: {
          showOnMenu: true,
          icon: 'image',
          title: '广告位',
          requirePermissions: 'create-post',
          breadcrumbs: [{routerName: 'content_picture', title: '图片内容', active: true}]
        },
        component: () => import('../views/admin/content_picture/contentPicture.vue')
      },

      {
        path: 'assets_manager',
        name: 'assets-manager',
        meta: {
          showOnMenu: true,
          icon: 'social-wordpress',
          title: '素材',
          requirePermissions: '',
          breadcrumbs: [{routerName: 'assets-manager', title: '素材管理', active: true}]
        },
        component: () => import('../views/admin/assets_manager/assets_manager.vue')
      }
    ]
  },
  {
    path: '/admin/setting',
    name: 'setting',
    component: AdminMain,
    meta: {
      showOnMenu: true,
      requireAuth: true,
      icon: 'ios-gear',
      title: '设置'
    },
    children: [
      {
        path: 'category',
        name: 'setting_category',
        meta: {
          showOnMenu: true,
          title: '分类设置',
          icon: 'grid',
          requirePermissions: 'edit-user',
          breadcrumbs: [{routerName: 'setting_category', title: '分类设置', active: true}]
        },
        component: () => import('../views/admin/category/category_num.vue')
      },
      {
        path: 'property',
        name: 'setting_property',
        meta: {
          showOnMenu: true,
          title: '参数设置',
          icon: 'wrench',
          requirePermissions: 'edit-user',
          breadcrumbs: [{routerName: 'setting_property', title: '参数设置', active: true}]
        },
        component: () => import('../views/admin/property/property.vue')
      },
      {
        path: 'site-settings',
        name: 'site_settings',
        meta: {
          showOnMenu: true,
          title: '网站设置',
          icon: 'xbox',
          requirePermissions: '',
          breadcrumbs: [{routerName: 'site_settings', title: '网站设置', active: true}]
        },
        component: () => import('../views/admin/site_setting/site_settings.vue')
      },
      {
        path: 'admin-manager',
        name: 'admin_manager',
        meta: {
          showOnMenu: true,
          title: '管理员设置',
          icon: 'ios-people',
          requirePermissions: 'edit-user',
          breadcrumbs: [{routerName: 'admin_manager', title: '管理员设置', active: true}]
        },
        component: () => import('../views/admin/admin_manager/manager.vue')
      }
    ]
  }
]

export const routers = [
  // loginRouter,
  siteRouter,
  ...adminRouter,
  // ...adminOtherRouter,
  ...errorRouter
]